﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Xml.Linq;
using XinGuanERP.Attributes.system;
using XinGuanERP.Models.Vo.system;
using XinGuanERP.Services.system.IServices;
using XinGuanERP.Utils;

namespace XinGuanERP.Controllers.system
{
    [DynamicApiController]
    public class DictEntryController
    {
        private readonly IDictEntryService _dictEntryService;

        public DictEntryController(IDictEntryService dictEntryService)
        {
            _dictEntryService = dictEntryService;
        }

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil GetDictEntryWithPage(int page, int pageSize, string? dictId, string? label)
            => ResultUtil.ok(_dictEntryService.GetDictEntryWithPage(page, pageSize, dictId, label));

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil PostDictEntry(DictEntryVo viewDictEntry)
            => ResultUtil.ok(_dictEntryService.UpdateDictEntry(viewDictEntry));

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil DeleteDictEntry(string id)
            => ResultUtil.ok(_dictEntryService.DeleteDictEntry(id));

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil GetDictEntryWithListByDictCode(string dictCode)
            => ResultUtil.ok(_dictEntryService.GetDictEntryWithListByDictCode(dictCode));
    }
}
